//
//  DistanceController.swift
//  HHSwift
//
//  Created by 华宏 on 2020/9/8.
//  Copyright © 2020 huahong. All rights reserved.
//

import UIKit

class DistanceController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "距离传感器"
        
        //启用靠近传感器
        UIDevice.current.isProximityMonitoringEnabled = true
        NotificationCenter.default.addObserver(forName: UIDevice.proximityStateDidChangeNotification, object: self, queue: OperationQueue.main) { (notification) in
            
            if UIDevice.current.proximityState == true {
               
                print("靠近")
            }else{
               print("远离")
            }
         }
        
    }
    

    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }

}
